import Vue from 'vue'
import Router from 'vue-router'
import { getUrlParamByKey } from 'vue-xiaobu-utils'

Vue.use(Router)

const BusCardRecharge = () =>
  import(
    /* webpackChunkName: "recharge/BusCardRecharge" */ '../page/BusCardRecharge.vue'
  )
const StaffCardRecharge = () =>
  import(
    /* webpackChunkName: "recharge/StaffCardRecharge" */ '../page/StaffCardRecharge.vue'
  )

const router = new Router({
  routes: [
    {
      path: '/busCardRecharge',
      component: BusCardRecharge,
      name: 'busCardRecharge'
    },
    {
      path: '/staffCardRecharge',
      component: StaffCardRecharge,
      name: 'staffCardRecharge'
    }
  ]
})
router.beforeEach((to, from, next) => {
  console.log('~~~from.path', from.path)
  console.log('~~~to.path', to.path)
  let path = '/busCardRecharge'
  try {
    if (parseInt(getUrlParamByKey('staff')) === 1) {
      path = '/staffCardRecharge'
    }
  } catch (error) {}
  // console.log('~~~to.path', to.path)
  if (path !== to.path) {
    router.replace({ path: path })
  }
  next()
})
export default router
